<?php
$time = microtime(TRUE);
error_reporting(E_ALL^E_USER_DEPRECATED^E_DEPRECATED^E_NOTICE);

define('HOST_SERVER_IP', '127.0.0.1');
define('HOST_SERVER_NAME', 'localhost');
define('DEFAULT_PROJECT', 'root');
define('DIR_CORE_PROJECT', 'app');
define('DIR_JABEZ_CORE', 'app');
define('DIR_PLUGIN_CORE', 'app');
define('DIR_PACKAGE_CORE', 'app');
define('WWW_ROOT', 'www');
define('WWW_JABEZ', 'www');

$match = array();
if(preg_match('/^url\=\/(\.|plugin(?:s)?)?(?(1)|([^\/]+))/i', htmlentities(strip_tags(urldecode($_SERVER['QUERY_STRING'])), ENT_QUOTES, 'UTF-8'), $match)) {

	if(empty($match[1]) && substr_count($match[2], '.') > 0) {

		$appName =& explode('.', strtolower(preg_replace('/(?<=[a-zA-Z0-9\_])([A-Z]{1,1})/', '-\1', $match[2])), 2);

		if(!preg_match('/core/i', &$appName[0])) {

			define('ACTIVE_PROJECT', $appName[0]);
			define('IS_DEFAULT_PROJECT', FALSE);
		}

		else {

			define('ACTIVE_PROJECT', DEFAULT_PROJECT);
			define('IS_DEFAULT_PROJECT', FALSE);
		}
	}

	else {

		define('ACTIVE_PROJECT', DEFAULT_PROJECT);
		define('IS_DEFAULT_PROJECT', TRUE);
	}
}

else {

	define('ACTIVE_PROJECT', DEFAULT_PROJECT);
	define('IS_DEFAULT_PROJECT', TRUE);
}

unset($match, $appName);

define('DS', DIRECTORY_SEPARATOR);
define('DOCUMENTO_RAIZ', str_replace('/', DS, $_SERVER['DOCUMENT_ROOT'] . DS));
define('DOCUMENT_ROOT', DOCUMENTO_RAIZ);
define('BOOT_PROJECT', ACTIVE_PROJECT . DS);
define('WWW_PROJECT', WWW_ROOT . DS);
define('WWW_CORE', WWW_JABEZ . DS);
define('DIR_BASE_NAME', basename(dirname(__FILE__)));
define('DIR_ROOT', DIR_BASE_NAME . DS);
define('PATH_ROOT', DOCUMENTO_RAIZ . DIR_ROOT);
define('PROJECT', DOCUMENTO_RAIZ . DIR_ROOT . BOOT_PROJECT);
define('HTTP_HOST', $_SERVER['HTTP_HOST']);
define('HTTP_URL', 'http://' . HTTP_HOST . '/');
define('HTTPS_URL', 'https://' . HTTPS_HOST . '/');
define('JABEZ', DOCUMENTO_RAIZ . DIR_ROOT . 'jabez' . DS);
define('JABEZ_CORE', JABEZ . DIR_JABEZ_CORE . DS);
define('PROJECT_CORE', PROJECT . DIR_CORE_PROJECT . DS);
define('REMOTE_ADDR', $_SERVER['REMOTE_ADDR']);
define('SERVER_ADDR', $_SERVER['SERVER_ADDR']);
define('HTTP_USER_AGENT', $_SERVER['HTTP_USER_AGENT']);

if(preg_match('/'.preg_quote(HOST_SERVER_IP).'|'.preg_quote(HOST_SERVER_NAME).'/i', HTTP_HOST)) {

	define('HOST_IS_PRIVATE', TRUE);
}

else {

	define('HOST_IS_PRIVATE', FALSE);
}

if(file_exists(PROJECT . WWW_PROJECT . 'index.php') && is_file(PROJECT . WWW_PROJECT . 'index.php')) {

	include_once(PROJECT . WWW_PROJECT . 'index.php');
}

else {

	include_once(JABEZ . WWW_CORE . 'index.php');
}

echo '<br><br><br><br>'.\Core\Uses\MemoriaUtilizada();
echo '<br><br><br><br>'.(microtime(TRUE) - $time);
//\core\uses\dump(\Core\Libs\JabezSingleton\JabezSingleton::getArrayInstances());
if(\Core\Uses\isContentCompression()) {

	ob_end_flush();
}
?>